package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysCalongService;
import com.sykj.manage.model.SysCatalog;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;

/**
 * 
 * @author 高志远
 *2018年9月14日下午2:27:43
 *类描述：分类科目[sys_catalog控制类
 */
@Controller
@RequestMapping("/sys")
public class SysCatalogController {
	@Autowired
	SysCalongService sysCalongService;
	
	
	@RequestMapping("/findCatalog")
	@ResponseBody
	public ManageBody index(SysCatalog sysCatalog,Model model,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysCatalog> sysCatalogs = sysCalongService.findCatalogs(sysCatalog);
		PageInfo<SysCatalog> pageInfo = new PageInfo<SysCatalog>(sysCatalogs);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	
	@RequestMapping("/findCatalogs")
	@ResponseBody
	public Object indexs(SysCatalog sysCatalog){
		List<SysCatalog> sysCatalogs = sysCalongService.findCatalogs(sysCatalog);
		return sysCatalogs;
	}
	
	/**
	 *
	 * @param catalog_id
	 * @return
	 * 分类科目删除
	 */
	@RequestMapping("/delCatalogs")
	@ResponseBody
	public Object delCatalogs(@RequestParam("catalog_id")String[] catalog_id) {
		int cnt = sysCalongService.delCatalogs(catalog_id);
		return cnt;
	}
	
	/**
	 * 
	 * @param sysCatalog
	 * @return
	 * 添加
	 */
	@RequestMapping("/addCatalog")
	@ResponseBody
	public Object addCatalog(SysCatalog sysCatalog){
		Date date = new Date();
		sysCatalog.setCreate_time(date);
		int addCatalog= sysCalongService.addCatalog(sysCatalog);
		return addCatalog;
		
	}
	
	/**
	 * 
	 * @param catalog_id
	 * @return
	 * 根据ID查询
	 */
	@RequestMapping("/findCatalogById")
	@ResponseBody
	public Object findCatalogById(String catalog_id) {
		SysCatalog findcatalog = sysCalongService.findCataById(catalog_id);
		return findcatalog;
	}
	
	@RequestMapping("/updCatalog")
	@ResponseBody
	public Object updCatalog(SysCatalog sysCatalog){
		Date date = new Date();
		sysCatalog.setCreate_time(date);
		int updCatalog= sysCalongService.updCatalog(sysCatalog);
		return updCatalog;
		
	}
	
	/**
	 * 字典科目ID查询
	 * @return
	 */
	@RequestMapping("/findDicCatalogID")
	@ResponseBody
	public Object findDicCatalogID() {
		List<SysCatalog> catalogs = sysCalongService.findDicCatalogID();
		return catalogs;
	}
	

}
